package com.bytz.modules.cms.productLine.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bytz.common.api.vo.Result;
import com.bytz.modules.cms.productLine.entity.ProductLineLevelLimit;
import com.bytz.modules.cms.productLine.model.LevelLimitImportRequest;
import com.bytz.modules.cms.productLine.model.ProductLineLevelLimitModel;
import com.bytz.modules.cms.productLine.service.IAdminProductLineLevelLimitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "产品线等级排外商品")
@RequestMapping("/productLineLevelLimit")
public class ProductLineLevelLimitController {

    @Autowired
    private IAdminProductLineLevelLimitService productLineLevelLimitService;

    @ApiOperation(value = "分页查询", notes = "分页查询")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result<IPage<ProductLineLevelLimitModel>> page(ProductLineLevelLimitModel productLineLevelLimit,
                                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                          HttpServletRequest req) throws Exception {

        return Result.ok(productLineLevelLimitService.page(new Page<>(pageNo, pageSize), productLineLevelLimit, req.getParameterMap()));
    }

    @ApiOperation(value = "查询单条", notes = "查询单条")
    @RequestMapping(value = "/queryById", method = RequestMethod.GET)
    public Result<ProductLineLevelLimit> queryById(@RequestParam String id) {

        return Result.ok(productLineLevelLimitService.getById(id));
    }

    @ApiOperation(value = "删除一条", notes = "删除一条")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Result<Boolean> delete(@RequestParam String id) {

        return Result.ok(productLineLevelLimitService.removeById(id));
    }

    @ApiOperation(value = "批量导入", notes = "批量导入")
    @RequestMapping(value = "/import", method = RequestMethod.POST)
    public Result<Boolean> importByNumbers(@RequestBody LevelLimitImportRequest request) {

        return Result.ok(productLineLevelLimitService.importByNumbers(request));
    }

}
